FROM jenkins
USER root

RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers

# 用户组权限问题
ARG dockerGid=999
RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group

#JDK
RUN wget --no-check-certificate --no-cookies --header \
    "Cookie: oraclelicense=accept-securebackup-cookie" \
    http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz &&\
    tar -zxvf jdk-8u131-linux-x64.tar.gz &&\
    rm jdk-8u131-linux-x64.tar.gz && \
    mv jdk1.8.0_131 /usr/local/jdk

#MAVEN
ENV MAVEN_VERSION=3.5.2
RUN wget http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz && \
  tar -zxvf apache-maven-$MAVEN_VERSION-bin.tar.gz && \
  rm apache-maven-$MAVEN_VERSION-bin.tar.gz && \
  mv apache-maven-$MAVEN_VERSION /usr/local/maven

ENV JAVA_HOME /usr/local/jdk
ENV CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV MAVEN_HOME /usr/local/maven
ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin

# for test mvn/java command
RUN mvn -version
RUN java -version

#时区
ENV TZ=Asia/Shanghai
ENV LANG="zh_CN.UTF-8"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && echo "export LC_ALL=zh_CN.UTF-8"  >>  /etc/profile

#test time
RUN date

USER jenkins

#run
sudo docker run -p 8080:8080 -p 50000:50000 --name jenkins \
--restart=always \
-v $(which docker):/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /opt:/opt \
-v /usr/share/maven:/usr/local/maven \
-v /opt/jenkins_home:/var/jenkins_home \
-v ~/.ssh:/var/jenkins_home/.ssh \
-v /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7 \
-d ssm/jenkins:1.0



-v /etc/timezone:/etc/timezone
-v /etc/localtime:/etc/localtime